<template>
	<view class="fui-wrap">
		<plateNumber :is-admin="true" ref="plateNumber" :value="plate_begin" @confirm="confirmPlate" @cancel="cancelPlate"></plateNumber>
		<fui-modal :show="pay.show" descr="请选择支付项目" :buttons="buttons" :radius="16" :maskClosable="true" direction="column" @click="clickButton" @cancel="cancelButton"></fui-modal>
	</view>
</template>

<script>
	import {methods,baseUrl} from '@/utils/core.js';
	import plateNumber from '@/components/common/plate.vue';
	export default {
		components:{
			plateNumber:plateNumber
		},
		data() {
			return {
				type:'',
				plate_begin:'',
				buttons:[{
					text: '临停缴费',
					background: '#22b2ff'
				}, {
					text: '月卡充值',
					background: '#FFB703'
				}, {
					text: '储值卡充值',
					background: '#1ab445'
				}],
				pay:{
					show:false,
					plate_number:''
				}
			}
		},
		onLoad(e) {
			this.type=e.type;
			if(e.plate_number){
				this.plate_begin=e.plate_number;
				return;
			}
			let parking=uni.getStorageSync('parking') || '';
			if(parking){
				this.plate_begin=parking.plate_begin;
			}
		},
		methods: {
			...methods,
			cancelPlate:function(){
				this.$navigateBack();
			},
			confirmPlate:function(plate_number){
				if(this.type=='search'){
					this.$redirectTo('parking/records/search?plate_number='+plate_number);
				}
				if(this.type=='input'){
					uni.setStorageSync('plate_number',plate_number);
					this.$navigateBack();
				}
				if(this.type=='pay'){
					this.$refs.plateNumber.hideKeyboard();
					this.pay={
						show:true,
						plate_number:plate_number
					};
				}
				if(this.type=='monthly_pay'){
					this.$redirectTo('parking/cars/recharge?rules_type=monthly&plate_number='+plate_number);
				}
				if(this.type=='stored_pay'){
					this.$redirectTo('parking/cars/recharge?rules_type=stored&plate_number='+plate_number);
				}
			},
			clickButton:function(e){
				if(e.index===0){
					this.$redirectTo('parking/records/pay?plate_number='+this.pay.plate_number);
				}
				if(e.index===1){
					this.$redirectTo('parking/cars/recharge?rules_type=monthly&plate_number='+this.pay.plate_number);
				}
				if(e.index===2){
					this.$redirectTo('parking/cars/recharge?rules_type=stored&plate_number='+this.pay.plate_number);
				}
			},
			cancelButton:function(){
				this.$refs.plateNumber.showKeyboard();
				this.pay={
					show:false,
					plate_number:''
				};
			}
		}
	}
</script>

<style lang="scss" scoped>
	.fui-wrap {
		background-color: #fff;
		padding-bottom: 40rpx;
	}
	.topwite{
		display: flex;
		margin-bottom: 20rpx;
	}
</style>